﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Utilities;
using InfoSoftGlobal;

public partial class OnTime : System.Web.UI.Page 
{
    private struct DeliverableStatus
    {
        public string WebName;
        public int NotStarted;
        public int InProgress;
        public int Completed;
        public int Deferred;
        public int Waiting;
    }

    private struct DeliverableResource
    {
        public string WebName;
        public int DeliverableCount;
    }

    private struct DeliverableProgress
    {
        public string WebName;
        public int ProgressCount;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        FCLiteral.Text = CreateDeliverableOnTimeChart();

       
    }

    public string CreateDeliverableOnTimeChart()
    {
        string sqlCon = System.Configuration.ConfigurationManager.ConnectionStrings["FastSharePoint"].ConnectionString;

        System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(sqlCon);
        System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("GetDeliverableProgress", con);

        cmd.CommandType = System.Data.CommandType.StoredProcedure;

        con.Open();

        System.Data.SqlClient.SqlDataReader dr = cmd.ExecuteReader();
        System.Collections.ArrayList projects = new System.Collections.ArrayList();

        while (dr.Read())
        {
            DeliverableProgress deliverable = new DeliverableProgress();
            deliverable.WebName = (string)dr["WebName"];
            deliverable.ProgressCount = (int)dr["Progress"];

            projects.Add(deliverable);
        }

        con.Close();

        string strXML; int i;

        //strXML = "<graph caption='Breakdown of Project Status' subCaption='(into Products and Services)' xAxisName='Project' yAxisMaxValue='5' numberSuffix='%' areaBorderColor='FFFFFF' showValues='0' numVDivLines='6' palette='5'>";
        strXML = "<graph caption='Deliverables On-Time Progress' numberPrefix='%' xAxisName='Resources' yAxisMaxValue='100' decimalPrecision='0' areaBorderColor='FFFFFF' showValues='0' numVDivLines='10' palette='5'>";

        for (i = 0; i < projects.Count; i++)
        {
            DeliverableProgress deliverable = (DeliverableProgress)projects[i];
            if (deliverable.ProgressCount > 74)
                strXML += "<set name='" + deliverable.WebName + "' value='" + deliverable.ProgressCount.ToString() + "' color='006F00' />";
            else
                strXML += "<set name='" + deliverable.WebName + "' value='" + deliverable.ProgressCount.ToString() + "' color='FF0000' />";
        }

        strXML += "</graph>";

        //Create the chart - Column 3D Chart with data contained in strXML
        return FusionCharts.RenderChart("../FusionCharts/FCF_Column3D.swf", "", strXML, "productSales", "450", "300", false, false);


    }

    //public string CreateDeliverableResourceChart()
    //{
    //    string sqlCon = System.Configuration.ConfigurationManager.ConnectionStrings["FastSharePoint"].ConnectionString;

    //    System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(sqlCon);
    //    System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("GetDeliverableResources", con);

    //    cmd.CommandType = System.Data.CommandType.StoredProcedure;

    //    con.Open();

    //    System.Data.SqlClient.SqlDataReader dr = cmd.ExecuteReader();
    //    System.Collections.ArrayList projects = new System.Collections.ArrayList();

    //    while (dr.Read())
    //    {
    //        DeliverableResource deliverable = new DeliverableResource();
    //        deliverable.WebName = (string)dr["UserName"];
    //        deliverable.DeliverableCount = (int)dr["DeliverableCount"];

    //        projects.Add(deliverable);
    //    }

    //    con.Close();

    //    string strXML; int i;

    //    //strXML = "<graph caption='Breakdown of Project Status' subCaption='(into Products and Services)' xAxisName='Project' yAxisMaxValue='5' numberSuffix='%' areaBorderColor='FFFFFF' showValues='0' numVDivLines='6' palette='5'>";
    //    strXML = "<graph caption='Breakdown of Deliverables' subCaption='(By Resource)' xAxisName='Resources' yAxisMaxValue='10' decimalPrecision='0' areaBorderColor='FFFFFF' showValues='0' palette='5'>";

    //    for (i = 0; i < projects.Count; i++)
    //    {
    //        DeliverableResource deliverable = (DeliverableResource)projects[i];
    //        strXML += "<set name='" + deliverable.WebName + "' value='" + deliverable.DeliverableCount.ToString() + "' color='AFD8F8' />";
    //    }

    //    strXML += "</graph>";

    //    //Create the chart - Column 3D Chart with data contained in strXML
    //    return FusionCharts.RenderChart("FusionCharts/FCF_Column3D.swf", "", strXML, "productSales", "450", "300", false, false);


    //}
}
